package com.coai.rtc.config

import org.springframework.context.annotation.Configuration
import org.springframework.messaging.simp.config.MessageBrokerRegistry
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker
import org.springframework.web.socket.config.annotation.StompEndpointRegistry
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer

@Configuration
@EnableWebSocketMessageBroker
class WebSocketConfig : WebSocketMessageBrokerConfigurer {
    
    override fun registerStompEndpoints(registry: StompEndpointRegistry) {
        registry.addEndpoint("/rtc-ws")
            .setAllowedOriginPatterns("*")
            .withSockJS()
    }
    
    override fun configureMessageBroker(registry: MessageBrokerRegistry) {
        // 简单消息代理
        registry.enableSimpleBroker("/topic", "/queue", "/user")
        
        // 应用目的地前缀
        registry.setApplicationDestinationPrefixes("/app")
        
        // 用户目的地前缀
        registry.setUserDestinationPrefix("/user")
    }
}
